const axios = require('axios')
module.exports = {
  namespaced: true,
  state: {
    list: [],
    param: {
      selectType: "",
      inputVulue: "",
      pageNum: 5,
      currentPage: 1
    },
    total: 0
  },
  mutations: {
    getOrder(state, data) {
      state.list = data.rows;
      state.total = data.total;
      state.list.forEach(item => {
        if (item.orderBool == "toBeConfirmed") {
          item.orderBool = "等待确认";
          item.price="未支付"
        } else if (item.orderBool == "unpaid") {
          item.orderBool = "待支付";
          item.price="未支付"
        } else if (item.orderBool == "transactionFailure") {
          item.orderBool = "交易失败";
          item.price="支付失败"
        } else if (item.orderBool == "paid") {
          item.orderBool = "已支付";
        } else if (item.orderBool == "dealClose") {
          item.orderBool = "交易完成";
        } else {
          item.orderBool = "等待确认";
        }
      });
    },
    firstPages(state) {
      state.param.currentPage = 1;
    },
    previouss(state) {
        if (state.param.currentPage <= 1) {
          state.param.currentPage = 1;
        } else {
          state.param.currentPage = parseInt(state.param.currentPage - 1);
        }
    },
    mynextPages(state) {
        const num = Math.ceil(state.total / state.param.pageNum);
        if (state.param.currentPage >= num) {
          state.param.currentPage = num;
        } else {
          state.param.currentPage = state.param.currentPage + 1;
        }
      },
    maxPages(state) {
          const num = Math.ceil(state.total / state.param.pageNum);
          state.param.currentPage = num;
    },
    search(state,data){
      state.param.selectType = data.rentName
      state.param.inputVulue = data.hireName
    }
  },
  actions: {
    async getOrderAsync({ commit, state }) {
      let { data } = await axios.get("/order/getOrderAll", {
        params: state.param
      });
      commit('getOrder', data)
    }
  }
}